package com.nextbusmn.server.JSONBuilders;

import com.google.appengine.labs.repackaged.org.json.JSONArray;
import com.google.appengine.labs.repackaged.org.json.JSONException;
import com.google.appengine.labs.repackaged.org.json.JSONObject;

import java.util.List;
import com.nextbusmn.server.dataobjects.ShapeData;

public class ShapeJSONBuilder {
	
	public static JSONArray getShapeJSON(List<ShapeData> shapeData) {
		JSONArray returnArray = new JSONArray();
		try {
			
			for (ShapeData row : shapeData) {
				JSONObject obj = new JSONObject();
				
				obj.put("x", (int) Math.floor(row.getShapePtLon() * 1000000.0));
				obj.put("y", (int) Math.floor(row.getShapePtLat() * 1000000.0));
				returnArray.put(obj);
			}
			
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
		return returnArray;
	}
}
